package com.aaa.member.controller;

import com.aaa.common.constants.ReturnCode;
import com.aaa.common.util.Result;
import com.aaa.member.entity.Coupon;
import com.aaa.member.service.CouponService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (Coupon)表控制层
 *
 * @author LiangLei
 * @since 2020-11-19 15:18:28
 */
@RestController
@RequestMapping("coupon")
public class CouponController {
    /**
     * 服务对象
     */
    @Resource
    private CouponService couponService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public Coupon selectOne(Integer id) {
        return this.couponService.queryById(id);
    }

    /**
     *  分页
     */
    @GetMapping("queryPageByParam")
    Result queryPageByParam(Integer pageNo, Integer pageSize, Coupon coupon){
        return this.couponService.queryPageByParam(pageNo,pageSize,coupon);
    }



    @PostMapping("add")
    public Result add(@RequestBody Coupon coupon){
        //返回成功
        return new Result(ReturnCode.SUCCESSS.getCode(),
                ReturnCode.SUCCESSS.getMsg(),this.couponService.insert(coupon));
    }



    @DeleteMapping("delete")
    public Result delete(Integer id){
        //返回成功
        return new Result(ReturnCode.SUCCESSS.getCode(),
                ReturnCode.SUCCESSS.getMsg(),this.couponService.deleteById(id));
    }


    /**
     * 更新
     * @param coupon
     * @return
     */
    @PutMapping("update")
    public Result update(@RequestBody Coupon coupon){
        return new Result(ReturnCode.SUCCESSS.getCode(),
                ReturnCode.SUCCESSS.getMsg(),this.couponService.update(coupon));
    }

}